package com.hdsx.jxcsxm.shares.server.impl;

import com.hdsx.dao.query.base.BaseOperate;
import com.hdsx.jxcsxm.funds.bean.FundBean;
import com.hdsx.jxcsxm.shares.bean.JhxdwhBean;
import com.hdsx.jxcsxm.shares.bean.ShareBean;
import com.hdsx.jxcsxm.shares.server.ShareServer;
import com.hdsx.jxcsxm.zjdw.bean.XmZjdw;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @author 占贤银
 * time 2024/2/26 10:18
 * description 生命之灯因热情而点燃，生命之舟因拼搏而前行
 */
@Service
public class ShareServerImpl extends BaseOperate implements ShareServer {

    public ShareServerImpl() {
        super("shares", "jdbc");
    }

    @Override
    public List<ShareBean> queryXmlist(ShareBean shareBean) {
        return queryList("queryXmlist", shareBean);
    }

    @Override
    public List<ShareBean> queryJhXmlist(ShareBean shareBean) {
        return queryList("queryJhXmlist", shareBean);
    }

    @Override
    public int queryXmlistCount(ShareBean shareBean) {
        return queryOne("queryXmlistCount", shareBean);
    }

    @Override
    public int queryJhXmlistCount(ShareBean shareBean) {
        return queryOne("queryJhXmlistCount", shareBean);
    }

    @Override
    public ShareBean getTjAll(ShareBean shareBean) {
        return queryOne("getTjAll", shareBean);
    }

    @Override
    public ShareBean getJhTjAll(ShareBean shareBean) {
        return queryOne("getJhTjAll", shareBean);
    }

    @Override
    public List<JhxdwhBean> getSharejhxdwh(ShareBean shareBean) {
        return queryList("getSharejhxdwh", shareBean);
    }

    @Override
    public ShareBean getdwTj(ShareBean shareBean) {
        return queryOne("getdwTj", shareBean);
    }

    @Override
    public ShareBean getbfTj(ShareBean shareBean) {
        return queryOne("getbfTj", shareBean);
    }

    @Override
    public List<JhxdwhBean> getWhTreeByNameShNew(ShareBean shareBean) {
        return queryList("getWhTreeByNameShNew", shareBean);
    }

    @Override
    public XmZjdw queryShqxByOne(XmZjdw xm) {
        return queryOne("queryShqxByOne", xm);
    }

    @Override
    public int insertShqx(List<XmZjdw> xm) {
        return insertBatch("insertShqx", xm);
    }

    @Override
    public int updateShqx(List<XmZjdw> xm) {
        return updateBatch("updateShqx", xm);
    }

    @Override
    public ShareBean getJhxdZjById(ShareBean shareBean) {
        return queryOne("getJhxdZjById", shareBean);
    }

    @Override
    public ShareBean getzjdwById(ShareBean shareBean) {
        return queryOne("getzjdwById", shareBean);
    }

    @Override
    public List<ShareBean> queryChildGydw(ShareBean shareBean) {
        if("1".equals(shareBean.getGydw().substring(0,1))) {
            return queryList("queryChildGydwJtj", shareBean);
        }
        return queryList("queryChildGydw", shareBean);
    }

    @Override
    public List<XmZjdw> queryXmlistshqx(ShareBean shareBean) {
        return queryList("queryXmlistshqx", shareBean);
    }

    @Override
    public int queryXmlistshqxCount(ShareBean shareBean) {
        return queryOne("queryXmlistshqxCount", shareBean);
    }

    @Override
    public List<XmZjdw> queryzjxdlist(ShareBean shareBean) {
        return queryList("queryzjxdlist", shareBean);
    }

    @Override
    public int queryzjxdlistCount(ShareBean shareBean) {
        return queryOne("queryzjxdlistCount", shareBean);
    }

    @Override
    public FundBean getxmInfo(ShareBean shareBean) {
        return queryOne("getxmInfo", shareBean);
    }

    @Override
    public ShareBean queryshareFundByXmbm(XmZjdw xm) {
        return queryOne("queryshareFundByXmbm", xm);
    }

    @Override
    public int insertXmjbxxShareFund(XmZjdw xm) {
        int num1 = insert("insertXmjbxxShareFund", xm);
        int num2 = insert("insertShareFundJhxd", xm);
        return num1 + num2;
    }

    @Override
    public List<ShareBean> queryDepartment(ShareBean bean) {
        return queryList("queryDepartmentById", bean);
    }

    @Override
    public int queryZjdwCountByXmbm(ShareBean shareBean) {
        return queryOne("queryZjdwCountByXmbm", shareBean);
    }

    @Override
    public boolean delSharefundXm(ShareBean shareBean) {
        int num = delete("delSharefundXm", shareBean);
        int num1 = delete("delSharefundJhxdXm", shareBean);
        if (num > 0 && num1 > 0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean addSharefundData(ShareBean shareBean) {
        List<ShareBean> dwList = queryList("queryDepartmentById", shareBean);
        int num = 0;
        int num1 = 0;
        shareBean.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        String jhxdwh = shareBean.getJhxdwh().replaceAll("\\s*", "");
        for (ShareBean bean : dwList) {
            String gydwdm = bean.getGydwdm();
            shareBean.setGydwdm(gydwdm);
            shareBean.setGydw(bean.getGydw());
            shareBean.setXmbm("share" + shareBean.getXmnf() + gydwdm + jhxdwh);
            shareBean.setXmdj(gydwdm.startsWith("1") ? "农村" : "国省道");
            shareBean.setXmmc(shareBean.getXmnf() + bean.getGydw() + jhxdwh);
            shareBean.setJhxdwh(jhxdwh);
            num = insert("insertJhXmjbxxShareFund", shareBean);
            num1 = insert("insertJhShareFundJhxd", shareBean);
        }
        if (num >0 && num1 > 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<ShareBean> queryMarketXzqh(ShareBean shareBean) {
        return queryList("queryMarketXzqh", shareBean);
    }

    @Override
    public int queryShareFundByXzqh(ShareBean shareBean) {
        shareBean.setJhxdwh(shareBean.getJhxdwh().replaceAll("\\s*", ""));
        return queryOne("queryShareFundByXzqh", shareBean);
    }

    @Override
    public boolean importSharefund(List<Map> data) {
        int num = insertBatch("importBatchSharefund", data);
        int num1 = insertBatch("importBeanSharefundJhxd", data);
        return true;
    }

    @Override
    public ShareBean getdwByWhbj(ShareBean shareBean) {
        return queryOne("getJhxdByWh", shareBean);
    }
}
